added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / CSWinFormObjPersistence / ReadMe.txt
blob48813eb5cf3cb0ac36da0b68b31cd0a2578049ad
1 ===============================================================================
2     WINDOWS FORMS APPLICATION : CSWinFormObjPersistence Project Overview
3 ===============================================================================
5 /////////////////////////////////////////////////////////////////////////////
6 Summary:
8 The Object Persistance sample demonstrates how to persist an object's data 
9 between instances, so that the data can be restored the next time the object 
10 is instantiated. 
13 /////////////////////////////////////////////////////////////////////////////
14 Demo:
16 1. Build the solution and run.
17 2. Enter some value to Name, Age, Address field
18 3. Close the form. 
19 4. Run the app again. You can see these value keeps in the field.
22 /////////////////////////////////////////////////////////////////////////////
23 Code Logic:
25 This sample uses a binaray file "Customer.bin" to store the information.
27 1. Create a class names Customer with some properties, and make the whole class
28    as serializable by adding the Serializable attribute on top of the class 
29    definition. 
30    If you do not want to persist a field, mark it as NonSerialized. 
32 2. In the Form.Load event,check if the Customer.bin file exists, it the file 
33    exists, use BinaryFormatter.Deserialize method to retrieve the data stored 
34    in it, otherwise create a new instance of Customer class.
35    
36 3. In the Form.FormClosing event,use BinaryFormatter.Serialize method to 
37    serialize the customer information to the Customer.bin file.
40 /////////////////////////////////////////////////////////////////////////////
41 References:
42    
43 1. Walkthrough: Persisting an Object in Visual Basic .NET
44    http://msdn.microsoft.com/en-us/library/aa984468(VS.71).aspx
45    
46 2. Windows Forms General FAQ.
47    http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/77a66f05-804e-4d58-8214-0c32d8f43191
48    
50 /////////////////////////////////////////////////////////////////////////////